const fs = require("fs");
const Router = require("koa-router");
const { dynamicRequire, cacheDirs } = require("../utils/dynamic-require");

const router = new Router();

// 编辑阶段readdirSync替换fs.readdirSync获取子集文件名称
const readdirSync = cacheDirs(fs.readdirSync(__dirname), "Router");

readdirSync.forEach((file) => {
  if (file !== "index.js") {
    let r = dynamicRequire("./" + file, __dirname);
    router.use(r.routes());
  }
});

module.exports = router;
